package com.lei2j.adapter;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.junit.Test;

import com.lei2j.adapter.AdapterTest.EnumeratorIterator;

public class AdapterTest {

	@Test
	public void test1() {
		Duck mallerDuck = new MallerDuck();
		Turkey wildTurkey = new WildTurkey();
		mallerDuck.fly();
		mallerDuck.quack();
		wildTurkey.fly();
		wildTurkey.gobble();
		Duck adapterTurkey = new AdapterTurkey(wildTurkey);
		adapterTurkey.fly();
		adapterTurkey.quack();
	}
	
	@Test
	public void test3() {
		Hashtable<String, String> table = new Hashtable<>();
		EnumeratorIterator<String> iterator = new EnumeratorIterator<>(table.elements());
		while(iterator.hasNext()) {
			System.out.println(iterator.next());
		}
	}
	
	public static class EnumeratorIterator<E> implements Iterator<E> {

		private Enumeration<E> enumeration;
		
		public EnumeratorIterator(Enumeration<E> enumeration) {
			super();
			this.enumeration = enumeration;
		}

		@Override
		public boolean hasNext() {
			return enumeration.hasMoreElements();
		}

		@Override
		public E next() {
			return enumeration.nextElement();
		}
		
	}
}
